def prime(x):
    a = True
    for b in range(2, int(x ** 0.5) + 1):
        if x % b == 0:
            a = False
            break
    return a
c = int(input())
if c < 1000 or c > 9999:
    print(0)
else:
    dgts = str(c)
    mx = 0
    for d in range(len(dgts)):
        for e in range(d + 1, len(dgts) + 1):
            num = int(dgts[d:e])
            if prime(num):
                mx = max(mx, num)
    print(mx)
